#!/usr/bin/perl

use XML::XPath;
use XML::XPath::XMLParser;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q=new CGI;
print $q->header();

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

print $buffer;

@pairs = split(/&/, $buffer);

foreach $pair (@pairs){
	($name, $value) = split(/=/, $pair);
	$value =~ tr/+/ /;
	$value =~ s/%(..)/pack("C", hex($1))/eg;
	$FORM{$name} = $value;
}
$first_name = $FORM{name};


foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);        
	$value =~ tr/+/ /;        
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/g;   
	$name =~ tr/+/ /;        
	$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/g;      
	$input{$name} = $value;
	print $name." ".$value;
}
my $xp = XML::XPath->new(filename => 'prova.xml');
my $nodeset = $xp->find("//utente[name='$value']");
if($nodeset->size()==1){
	print "Utente loggato";
}
else{
	print "Utente non esistente";
}
